﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Manage_Link_xq : System.Web.UI.Page
{
    string LinkId = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            LinkId = SysFun.IsSQL(Request.Params["LinkId"].ToString());
            if (!IsPostBack)
            {

                Db db1 = new Db();
                System.Data.IDataReader dr;
                string strSql = "select LinkId,Title,LinkWWW,DownLoad,AddDate,IsShow from Link where LinkId=" + LinkId;
                dr = db1.DataReader(strSql);
                while (dr.Read())
                {
                    txtname.Text = dr["Title"].ToString();
                    Textwww.Text = dr["LinkWWW"].ToString();
                    RadioButtonList1.SelectedIndex = Convert.ToInt32(dr["IsShow"]);
                    if (dr["DownLoad"].ToString().Trim() != "")
                    {
                        Image1.ImageUrl = "../uploadfile/" + dr["DownLoad"].ToString();
                       
                    }
                    else
                    {
                        Image1.Visible = false;
                    }
                }
                dr.Close();
                dr.Dispose();
                db1.Close();
            }
        }
    }
    protected void Button5_Click(object sender, EventArgs e)//修改
    {
        HttpFileCollection files = HttpContext.Current.Request.Files;
        string sql;
        string LoadFileName = "";
        string fileName = "";
        string fileExtension = "";
        Boolean Useful = false;
        try
        {
            for (int iFile = 0; iFile < files.Count; iFile++)
            {
                ///'检查文件扩展名字

                HttpPostedFile postedFile = files[iFile];
               
                fileName = FileUpload1.FileName;
                LoadFileName = "";
                fileExtension = System.IO.Path.GetExtension(fileName);
                if (((fileExtension.ToUpper()) == ".JPG") || (fileExtension.ToUpper() == ".JPEG") || (fileExtension.ToUpper() == ".BMP"))
                {
                    Useful = true;
                }
                else
                {
                    Useful = false;
                }
                if (fileName != "" && Useful)
                {
                    //LoadFileName = fileName;
                    LoadFileName = SysFun.GetIntDate() + "-" + SysFun.GetIntTime() + "-" + SysFun.GetRnd(10000, 99999);



                    ///注意：可能要修改你的文件夹的匿名写入权限。

                    postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("../UploadFile/") + LoadFileName + fileExtension);


                }
            }
            if (Useful)
            {
                Db db = new Db();
                
                System.IO.File.Delete(Server.MapPath(Image1.ImageUrl));
                sql = "update Link set Title='" + txtname.Text.ToString().Trim() + "',LinkWWW='" + Textwww.Text.ToString().Trim() + "',AddDate=getdate(),AccountId=" + 1 + ",DownLoad='" + LoadFileName + fileExtension + "',IsShow =" + RadioButtonList1.SelectedIndex + " where LinkId=" + LinkId;
                db.Command(sql);
                db.Close();
                strStatus.Text = "保存成功！";
               // Response.Write("<script> location.href='link_xq.aspx?LinkId=" + LinkId + "';</script>");
                Response.Redirect("link_xq.aspx?LinkId=" + LinkId, true);

            }
            else
            {
                if (fileName == "")
                {
                    Db db = new Db();
                    sql = "update Link set Title='" + txtname.Text.ToString().Trim() + "',LinkWWW='" + Textwww.Text.ToString().Trim() + "',AddDate=getdate(),AccountId=" + 1 + ",IsShow =" + RadioButtonList1.SelectedIndex + " where LinkId=" + LinkId;
                    db.Command(sql);
                    db.Close();
                    strStatus.Text = "保存成功！";
                    Response.Redirect("link_xq.aspx?LinkId=" + LinkId, true);
                }
                else
                {
                    strStatus.Text = "只能上传图片文件格式(.JPG 、.JPEG .、.BMP)!";
                }


            }



        }
        catch (System.Exception Ex)
        {
            strStatus.Text = Ex.Message;


        }
    }
}
